<?php
	// Mã chủ đề
	$MaLCM = $_GET['mlcm']; 
	$sql="select loaichuyenmuc.TenLoaiChuyenMuc, chuyenmuc.TenChuyenMuc from loaichuyenmuc, chuyenmuc where chuyenmuc.MaChuyenMuc and loaichuyenmuc.MaLoaiChuyenMuc = $MaLCM";
	$dsloaichuyenmuc = mysql_query($sql);
	$tenloaichuyenmuc=mysql_fetch_array($dsloaichuyenmuc);
?>
<div id="ChuyenMucBaiViet">&nbsp<?php echo "<td class='hienthi'>Bạn đang ở: {$tenloaichuyenmuc['TenChuyenMuc']} <img src='adm/images/next.png'> {$tenloaichuyenmuc['TenLoaiChuyenMuc']} </td>"; ?></div>
<?php 
	if($_GET['page']) {
	$page = $_GET['page'];
	$current_page = $page;
	$page -= 1;
	$display = 5;
	$start = $page * $display;
	$data = "";
	$sql_baiviet_loaichuyenmuc = "SELECT *
								  FROM baiviet
								  WHERE MaLoaiChuyenMuc = $MaLCM and XuatBan = 1
								  LIMIT $start, $display";
	$danhsach_baiviet_loaichuyenmuc = mysql_query($sql_baiviet_loaichuyenmuc);
?>

<table class="NoBorder" width="700px">
	<?php
       
		while($dong_baiviet_loaichuyenmuc = mysql_fetch_array($danhsach_baiviet_loaichuyenmuc))
		{
            $tam = $dong_baiviet_loaichuyenmuc['TomTat'];
			echo "<tr>";
				echo "<td colspan='2' class='TieuDe'><a href='news.php?do=baivietchitiet&mbv={$dong_baiviet_loaichuyenmuc["MaBaiViet"]}'><h4>{$dong_baiviet_loaichuyenmuc['TieuDe']}</h4></a></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td colspan='2' class='NgayDang'>Ngày đăng: {$dong_baiviet_loaichuyenmuc['NgayDang']}</td>";
			echo "</tr>";
			$HinhAnhPath = substr($dong_baiviet_loaichuyenmuc["HinhAnh"], 3);
			echo "<tr>";
                echo "<td class='HinhAnh'><img width='100' height='100' src='{$HinhAnhPath}' /></td>";
				echo "<td align='justify' class='TomTat'>" . substr($dong_baiviet_loaichuyenmuc['TomTat'], 0, 500) . "</td>";
			echo "</tr>";
			echo "<tr>";
			echo "<td></td>";
			echo "<td class='btn_more'><a href='news.php?do=baivietchitiet&MLCM".$MaLCM."&mbv={$dong_baiviet_loaichuyenmuc['MaBaiViet']}'>Xem tiếp...</a></td>";
			echo "</tr>";
		}
	?>
</table>
<?php 
$data = "<nav role='list'>
			<ul>".$data."</ul>
		</nav>";
$query_page = "SELECT COUNT(*) FROM baiviet
								  WHERE MaLoaiChuyenMuc = $MaLCM and XuatBan = 1";
$result_page = mysql_query($query_page);
$row = mysql_fetch_array($result_page);
$count = $row['COUNT(*)'];
$pages = ceil($count / $display);

if ($current_page >= 7) 
{
	$start_page = $current_page - 3;
	if ($pages > $current_page + 3)
		$end_page = $current_page + 3;
	else if ($current_page <= $pages && $current_page > $pages - 6) 
	{
			$start_page = $pages - 6;
			$end_page = $pages;
	} 
	else 
	{
		$end_page = $pages;
	}
} 
else 
{
	$start_page = 1;
	if ($pages > 7)
		$end_page = 7;
	else
		$end_page = $pages;
}

$data .= "";
?>
<div style="text-align:center;">
<?php
if ($current_page > 1) 
{
	$data .= "<a href='news.php?do=baivietloaichuyenmuc&mlcm={$MaLCM}&page=1'>Đầu tiên</a>&nbsp";
	$previous = $current_page - 1;
	$data .= "<a href='news.php?do=baivietloaichuyenmuc&mlcm={$MaLCM}&page={$previous}'>Trước</a>&nbsp";
} 

for ($i = $start_page; $i <= $end_page; $i++) 
{
	if ($current_page == $i)
		$data .= "<b>{$i}</b>&nbsp";
	else
		$data .= "<a href='news.php?do=baivietloaichuyenmuc&mlcm={$MaLCM}&page={$i}'>{$i}</a>&nbsp";
}

if ($current_page < $pages) 
{
	$next = $current_page + 1;
	$data .= "<a href='news.php?do=baivietloaichuyenmuc&mlcm={$MaLCM}&page={$next}'>Tiếp</a>&nbsp";
	$data .= "<a href='news.php?do=baivietloaichuyenmuc&mlcm={$MaLCM}&page={$pages}'>Cuối</a>&nbsp";
} 

$total_page = "<span class='per_page'>Trang ". $current_page ." => $pages </span>";



echo $data;

}
?>
</div>




